flowchart LR
A[Raw Markdown] --> B{Extract Footnotes}
B -->|Content| C[Preprocess Super/Sub]
B -->|Footnote Defs| D[Store in Dict]
C --> E[Preprocess Tabs]
E -->|Content + Placeholders| F[Mistletoe Parser]
E -->|Tab Data| G[Tab Store]
F --> H[Token Stream]
H --> I{ContentRenderer}
I -->|BlockCode + 'mermaid'| J[Mermaid Renderer]
I -->|Link| K[Link Renderer]
I -->|FootnoteRef| L[Footnote Renderer]
I -->|Other| M[Standard HTML]
J --> N[Diagram with Controls]
K --> O{Relative/Internal?}
O -->|Relative| P[Resolve Path]
P --> Q[Add HTMX attrs]
O -->|Internal| Q
O -->|External| R[Add target=_blank]
L --> S[Sidenote Component]
D --> S
N --> T[Initial HTML]
Q --> T
R --> T
S --> T
M --> T
T --> U[Postprocess Tabs]
G --> U
U -->|Render Each Tab| V[ContentRenderer]
V --> U
U --> W[Apply CSS Classes]
W --> X[Final HTML]
style J fill:#ffe6cc
style L fill:#d1ecf1
style O fill:#fff3cd
style U fill:#e7d4ff